class MyQueue {
       constructor(capacity){
        this.array = new Array(capacity)
        this.front = 0;
        this.rear = 0;
       }
       enQueue (element) {
        if ((this.rear + 1) % this.array.length === this.front) {
            throw new Error('队列已满！')
        }
        this.array[this.rear] = element;
        this.rear = (this.rear + 1) % this.array.length;
    }
    deQueue() {
        if (this.rear === this.front) {
            throw new Error('队列已空！')
        }
        const deQueueElement = this.array[this.front]
        this.front = (this.front + 1) % this.array.length;
        return deQueueElement;
    }
    output() {
    
        if (this.rear === this.front) {
            throw new Error('空队列！')
        }
        for (let i=this.front; i != this.rear; i = (i+1)%this.array.length) {
            console.log(this.array[i]);
        }
    }
}

const myQueue = new MyQueue(6)
myQueue.enQueue(3)
myQueue.enQueue(5)
myQueue.enQueue(6)
myQueue.enQueue(8)
myQueue.enQueue(1)
myQueue.deQueue()
myQueue.deQueue()
myQueue.deQueue()
myQueue.enQueue(2)
myQueue.enQueue(4)
myQueue.enQueue(9)
myQueue.output()